package com.ticket.sass.admin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ticket.sass.common.entity.tenant.UserEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户表 Mapper 接口
 * </p>
 *
 * @author ywb
 * @since 2024-03-06
 */
public interface UserMapper extends BaseMapper<UserEntity> {
    
    
    @Select("""
        SELECT
            DATE(created_at) AS day,
            COUNT(*) AS user_count
        FROM
            public.users
        WHERE
            created_at >= #{startTime} AND
            created_at < #{endTime} AND
            deleted_at IS NULL
        GROUP BY
            DATE(created_at)
        ORDER BY
            day;
        """)
    List<Map<String, Object>> getUserCountByDay(@Param("startTime") LocalDate startTime, @Param("endTime") LocalDate endTime);
}
